#include <54func.h>
int DSPtree(char *dirpath,int width)
{
    
    DIR *dirp = opendir(dirpath);//根据文件名称去打开所在目录
    //ERROR_CHECK(dirp,NULL,"opendir");
    struct dirent *pdirent;
    while((pdirent = readdir(dirp))!=NULL)//readdir会读取目录，并将读取结果返回给结构体指针
    {
        //若是读取到最底层目录，则直接跳过
        if(strcmp(pdirent->d_name,".") == 0 ||
           strcmp(pdirent->d_name,"..") == 0)
        {
            continue;
        }
        for(int i=0;i<width;i++)
        {
            printf("-");
        }
        printf("%s\n",pdirent->d_name);
        //若是读取到目录，则递归读取
        if(pdirent->d_type == DT_DIR)
        {
            char path[1024]={0};
            sprintf(path,"%s%s%s",dirpath,"/",pdirent->d_name);
            DSPtree(path,width+6);//要传入的路径，肯定是当前了目录的子目录-->儿子
        }
    }

    closedir(dirp);
    return 0;

}
int main(int argc,char *argv[])
{
    // ./homework dir1
   ARGS_CHECK(argc,2);
   printf("%s\n",argv[1]);
   DSPtree(argv[1],6);
   return 0;
}
